<?php
/**
 * Created by PhpStorm.
 * User: nightelf
 * Date: 2020/1/11
 * Time: 10:44
 */

namespace App\Http\Model;


class Model
{
    private $attendance = [];
    /**
     * @param $startTime
     * @param $endTime
     * @param $period
     * @param $periodFormat
     * @param string $template
     * @return array
     * @throws \Exception
     */
    public function datePeriod($startTime, $endTime, $period, $periodFormat,$template='')
    {
        $result = [];
        $start = new \DateTime($startTime);
        $end = new \DateTime(date('Y-m-t 23:59:59',strtotime($endTime)));
        $interval = \DateInterval::createFromDateString($period);
        $period = new \DatePeriod($start, $interval, $end);
        switch ($template){
            case 'attendance':
                $t = ['day'=>'','projectName'=>'','long'=>'','projectId'=>'','isCurrent'=>1];
                break;
            case 'account':
                $t = ['day'=>'','projectName'=>'','account'=>0,'projectId'=>''];
                break;
            default:
                $t = [];
        }
        foreach ($period as $dt) {

            $result[$dt->format($periodFormat)] = $t;
        }
        return $result;
    }
}